<%-- 
    Document   : viewrestaurant
    Author     : Nina
               : Shasha
--%>

<%@ page import="webapp.model.Restaurant" %>
<%@ page import="webapp.model.Comment" %>
<%@ page import="webapp.model.UserManager" %>
<%@ page import="webapp.model.User" %>
<%@ page import="java.util.ArrayList" %>
<%
    Restaurant r = (Restaurant) request.getAttribute("restaurant");
    String restaurant_image_url = r.getId() + ".jpeg";
    if(r.getImage_url() != null)
        restaurant_image_url = r.getImage_url();

    ArrayList<Comment> comments = (ArrayList<Comment>) request.getAttribute("comments");

    int commentHeight = (comments == null) ? 0 : comments.size();


    //double rate = 0.0;
    
     String rate = r.getRating();
     String hours = r.getOpenHours();
     String price = r.getPriceRange();
     String phone = r.getPhone();
     String website = r.getWebsite();
     String address = r.getAddress();

    UserManager um = new UserManager();
   
%>

<%@include file="/includes/header.jsp" %>
<link href="includes/css/viewrecipe.css" rel="stylesheet" type="text/css">
<div id="body" style="height:<%=(600 + commentHeight * 210)%>px">
    <%@include file="/includes/menu.jsp" %>
    <div id="right">
        <%if(user_status){%>
            <div id="recipe_actions">
                <a id="rate" title="Rate" href="rate?restaurant_id=<%=r.getId() %>"><span>Rate Restaurant</span></a>
                <a id="comment" title="Comment" href="addcomment?restaurant_id=<%=r.getId() %>"><span>Review This Restaurant</span></a>
            </div>
        <%}%>
        <div class="view_recipe" id="recipe_<%=r.getId() %>">
            <img width="140" height="140" title="<%=r.getName()%>" src="restaurants/<%=restaurant_image_url %>" alt="delicious picture!"/>
            <p class="title"><%=r.getName()%></p>
            <p class="rating">Rating: <%=rate%>/5.0</p>
            <p class="rating">Open Hours: <%=hours%></p>
            <p class="rating">Price: <%=price%></p>
            <p class="rating">Phone Number: <%=phone%></p>
            <p class="rating">Website: <%=website%></p>
            <p class="rating">Address: <%=address%></p>
           
         
        </div>
        <div id="comments">
             <%if(comments != null){
                 for(int i = 0; i < comments.size(); i++){
                	User commentOwner = um.getUserByID(comments.get(i).getUser_id());                 
                    String owner_img_url = "default.jpg";
             %>
                 <ul>
                     <li class="image"><img width="80px" height="71px" src="users/<%=owner_img_url %>"/></li>
                     <li class="posted_date"><p>Posted: <%=comments.get(i).getDate() %></p></li>
                     <li class="posted_date"><p>By: <%=commentOwner.getUserName() %></p></li>
                     <li class="comment_text"><p><%=comments.get(i).getReview() %></p></li>
                 </ul>
             <%}
             }%>
        </div>
        <div class="view_recipe" id="recipe_<%=r.getId() %>">
   			<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    		<script type="text/javascript" src="jquery-1.4.4.min.js"></script>        
    		<script src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
    		<script type="text/javascript" src="gmap3.js"></script> 
    		<label>Address</label>
    		<input id="ResAdd" name="ResAdd" value='<%=address%>' size="50" maxlength="50" />
    		<style>
     			 .gmap3{
      			  margin: 20px auto;
       			  border: 1px dashed #C0C0C0;
        		  width: 500px;
        		  height: 250px;
      				}
    		</style>
    
    		<script type="text/javascript">
      		$(function(){
      			 var add = $("#ResAdd").val()
        	$('#test1').gmap3({
         	 marker:{
            address: add
          	},
          	map:{
           	 	options:{
             	zoom: 14
            			}
          	}
        	});
      		});
    		</script>
  			<body>
   			<div id="test1" class="gmap3"></div>
  			</body>
        </div>
 
<%@include file="/includes/footer.jsp" %>
